home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / utils / file / logiso.000 / logiso / Utils / process_lists.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-24  |  2.1 KB  |  81 lines

  1.  
  2. /* process_lists.c
  3.    USAGE: process_lists       inode_list_file    pair_list_file
  4.        inode list file is a file with one inode number on each line,
  5.            sorted numerically (ascending).  Should be run through uniq
  6.            also.
  7.         pair_list_file is a file with an inode number followed by a space
  8.             and a file path on each line.  It is also sorted
  9.             numerically (ascending).
  10.  
  11.         For each inode number which appears in both files, print the
  12.             file path from the pair_list_file.
  13.  
  14. */
  15. /* (C) Copyright 1995 by Michael Coulter.  All rights reserved. */
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19.  
  20. extern void print_usage();
  21.  
  22. #define FALSE        0
  23. #define TRUE         1
  24. #define MAX_FILE_PATH    2000
  25.  
  26. main(int argc, char** argv)
  27. {
  28.    char        file_path[MAX_FILE_PATH];
  29.    FILE*     inode_list_fp;
  30.    long int    inode1_nbr;
  31.    long int    inode2_nbr;
  32.    int        is_more_input;
  33.    FILE*     pair_list_fp;
  34.    int        result;
  35.  
  36.    if (argc != 3) {
  37.       print_usage();
  38.       exit(1);
  39.    }
  40.    if ((inode_list_fp = fopen(argv[1], "r") ) == NULL) {
  41.       print_usage();
  42.       fprintf(stderr, "Unable to open %s\n", argv[1]);
  43.       exit(1);
  44.    }
  45.    if ((pair_list_fp = fopen(argv[2], "r") ) == NULL) {
  46.       print_usage();
  47.       fprintf(stderr, "Unable to open %s\n", argv[2]);
  48.       exit(1);
  49.    }
  50.  
  51.    is_more_input = TRUE;
  52.    inode1_nbr = inode2_nbr = 0;
  53.    while (is_more_input) {
  54.       if (   inode1_nbr <= inode2_nbr
  55.           && (result = fscanf(inode_list_fp, "%ld", &inode1_nbr)) != 1) 
  56.       {
  57.          is_more_input = FALSE;
  58.       } else {
  59.      if (   inode2_nbr < inode1_nbr 
  60.          && (result = fscanf(pair_list_fp, "%ld %s", &inode2_nbr, file_path)) 
  61.             != 2) 
  62.          { 
  63.         is_more_input = FALSE;
  64.          } else {
  65.             if (inode1_nbr == inode2_nbr) {
  66.                fprintf(stdout, "%ld        %s\n", inode2_nbr, file_path);
  67.             }
  68.          }
  69.       }
  70.    } /* while input on both files */
  71.  
  72. } /* end main */
  73.  
  74.  
  75. void print_usage()
  76. {
  77.    fprintf(stderr, "USAGE: process_lists inode_list_file pair_list_file\n");
  78.    fprintf(stderr, "One inode number per line in the first file.\n");
  79.    fprintf(stderr, "An inode number and a file path per line in the second.\n");
  80. } /* end print_usage */
  81.